// pages/card_detail/index.js
const app     = getApp();
const request = require('../../utils/request.js');
const config = require('../../utils/config.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
      id:0,
      card_detail:null,
      showPop1:false,
      choose_id:0
    },
    togglePop1(){
        if(!this.data.showPop1){
          this.setData({
              choose_id:0,
          })
        }
      this.setData({
        showPop1:!this.data.showPop1
      })
    },
    choosetags(e){
      this.setData({
          choose_id:e.currentTarget.dataset.id
      })
    },
    showPop(){
      var that = this;
      if(that.data.card_detail.services.length==0){
          wx.showToast({
            title: '不可预约',
            icon:'none'
          })
          return false
      }
      that.setData({
        choose_id:0,
        showPop1:true
      })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
           id:options.id
        });
        this.getCardDetail();
    },
    getCardDetail()
    {
        var that = this;
        var json = {};
        json.id = that.data.id;
        request.requestLoading(
            "/api/appoint/rightsDetail",
            json,
            'GET',
        ).then((res) => {
            console.log(res)

            if(res.data){
                that.setData({
                    card_detail:res.data
                });


            }
            that.setData({
                is_show:true
            })

        }).catch((err) => {
            console.error(err);
        });
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },
    goappoints(){
        var json={},that =this;
        json.card_id=that.data.id;
        if(that.data.choose_id==0){
            wx.showToast({
              title: '请选择服务类型',
              icon:'none'
            })
            return false
        }
        request.requestLoading(
         "/api/mine/checkInfo",
         json,
         'POST',
       ).then((res) => {
        
        if(res.code==1){
            that.setData({
                showPop1:false
            })
            wx.navigateTo({
                url: '/pages/choose_hospital/index?card_id='+that.data.id+'&tags_id='+that.data.choose_id,
            })
        //  wx.navigateTo({
        //      url: '/pages/make_appointment/index?card_id='+that.data.card_id+'&hosptial_id='+e.currentTarget.dataset.id,
        //    })
        }
        
        
   
       }).catch((err) => {
         console.error(err);
       });
       
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
        this.getCardDetail();
        setTimeout(function(){
          wx.stopPullDownRefresh();
        },500)
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})